home *** CD-ROM | disk | FTP | other *** search
/ Sky at Night 2007 June / SAN CD 6-2007 CD-ROM 25.iso / pc / Software / AstroGrav_Win / Java / jre1.6.0 / lib / rt.jar / java / net / SocketOutputStream.class (.txt) < prev    next >
Encoding:
Java Class File  |  2006-11-29  |  1.7 KB  |  91 lines

  1. package java.net;
  2.  
  3. import java.io.FileDescriptor;
  4. import java.io.FileOutputStream;
  5. import java.io.IOException;
  6. import java.nio.channels.FileChannel;
  7. import sun.net.ConnectionResetException;
  8.  
  9. class SocketOutputStream extends FileOutputStream {
  10.    private PlainSocketImpl impl = null;
  11.    private byte[] temp = new byte[1];
  12.    private Socket socket = null;
  13.    private boolean closing = false;
  14.  
  15.    SocketOutputStream(PlainSocketImpl var1) throws IOException {
  16.       super(var1.getFileDescriptor());
  17.       this.impl = var1;
  18.       this.socket = var1.getSocket();
  19.    }
  20.  
  21.    public final FileChannel getChannel() {
  22.       return null;
  23.    }
  24.  
  25.    private native void socketWrite0(FileDescriptor var1, byte[] var2, int var3, int var4) throws IOException;
  26.  
  27.    private void socketWrite(byte[] var1, int var2, int var3) throws IOException {
  28.       if (var3 > 0 && var2 >= 0 && var2 + var3 <= var1.length) {
  29.          FileDescriptor var4 = this.impl.acquireFD();
  30.  
  31.          try {
  32.             this.socketWrite0(var4, var1, var2, var3);
  33.          } catch (SocketException var9) {
  34.             SocketException var5 = var9;
  35.             if (var9 instanceof ConnectionResetException) {
  36.                this.impl.setConnectionResetPending();
  37.                var5 = new SocketException("Connection reset");
  38.             }
  39.  
  40.             if (this.impl.isClosedOrPending()) {
  41.                throw new SocketException("Socket closed");
  42.             }
  43.  
  44.             throw var5;
  45.          } finally {
  46.             this.impl.releaseFD();
  47.          }
  48.  
  49.       } else if (var3 != 0) {
  50.          throw new ArrayIndexOutOfBoundsException();
  51.       }
  52.    }
  53.  
  54.    public void write(int var1) throws IOException {
  55.       this.temp[0] = (byte)var1;
  56.       this.socketWrite(this.temp, 0, 1);
  57.    }
  58.  
  59.    public void write(byte[] var1) throws IOException {
  60.       this.socketWrite(var1, 0, var1.length);
  61.    }
  62.  
  63.    public void write(byte[] var1, int var2, int var3) throws IOException {
  64.       this.socketWrite(var1, var2, var3);
  65.    }
  66.  
  67.    public void close() throws IOException {
  68.       if (!this.closing) {
  69.          this.closing = true;
  70.          if (this.socket != null) {
  71.             if (!this.socket.isClosed()) {
  72.                this.socket.close();
  73.             }
  74.          } else {
  75.             this.impl.close();
  76.          }
  77.  
  78.          this.closing = false;
  79.       }
  80.    }
  81.  
  82.    protected void finalize() {
  83.    }
  84.  
  85.    private static native void init();
  86.  
  87.    static {
  88.       init();
  89.    }
  90. }
  91.